﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.SharePoint;

namespace VH.SharePoint.Api.RSD
{
    public class RsdHandler: IHttpHandler
    {
        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.HttpMethod != "GET")
                throw new NotSupportedException();

            var response = context.Response;
            var web = SPContext.Current.Web;
            var blog = BlogWeb.GetBlogWeb(web);

            var rsd = new Rsd();
            rsd.Service.EngineName = "SharePoint 2010 Blogging Service";
            rsd.Service.EngineLink = "http://spblogging.codeplex.com/";
            rsd.Service.HomePageLink = web.Url;
            if (blog.IsEnabled)
            {
                rsd.Service.Apis.Add(
                    new Api { Name = "MetaWeblog", Preferred = true, ApiLink = web.Url+SPConstants.EndPointApi, BlogId = blog.Id.ToString()}
                    );
            }

            var xml = rsd.ToString();
            response.ContentType = "application/xml";
            response.Write(xml);


        }

    }
}
